package com.colorlight.cloud.complete.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;

import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Demon
 * @date 14/12/2023 下午4:02
 */
@Getter
public enum AdjustMode implements EnumTrans<Integer, AdjustMode> {
	/* 调节模式
	0 线性（有3个调节点）
	1 伽马（有2个调节点）
	2 反伽马（有2个调节点）
	3 自定义（有9个调节点） */
	LINEAR(0, "LINEAR"),
	GAMMA(1, "GAMMA"),
	ANTI_GAMMA(2, "ANTI_GAMMA"),
	USER_DEFINED(3, "USER_DEFINED");
	private final Integer value;
	private final String name;
	
	AdjustMode(int value, String name) {
		this.name = name;
		this.value = value;
	}
	
	/**
	 * @param value 编号
	 * @return 对应的类型
	 */
	public static AdjustMode getAdjustMode(Integer value) {
		Objects.requireNonNull(value, "AdjustMode can not be null.");
		return Arrays.stream(AdjustMode.values())
				.filter(e -> e.value.equals(value))
				.findFirst()
				.orElseThrow(() ->  new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
	}
	
	@Override
	public Integer toProto() {
		return this.getValue();
	}
	
	@Override
	public AdjustMode formProto(Integer integer) {
		return getAdjustMode(integer);
	}
}
